Overview
FF Messaging Service Documentation
The FF Messaging Service is a robust, scalable, and secure Flask-based messaging service that integrates REST APIs and WebSockets for real-time communication. This service is designed to handle both user-to-user and organization-to-organization messaging with features like offline message delivery, read receipts, and typing indicators.
Key Features
- User Authentication: JWT-based authentication for secure access
- Real-Time Communication: WebSocket support for instant messaging
- Offline Message Delivery: Store and forward functionality for offline users
- Read Receipts: Track when messages are read
- User Presence: Monitor online/offline status of users
- Rate Limiting: Configurable rate limits to prevent abuse
- Feature Flags: Toggle features without code deployment
- Comprehensive Logging: Structured logging for monitoring
- Scalable Architecture: Built with Redis and RabbitMQ
- Organization Support: Handle both user and organization-level messaging
Technical Stack
- Framework: Flask + Flask-SocketIO
- Database: MongoDB for message storage
- Cache: Redis for session management and rate limiting
- Message Queue: RabbitMQ for asynchronous processing
- Documentation: Self-documenting API
- Runtime: Python 3.12+
System Requirements
- Python 3.12.6 or higher
- MongoDB 5.0+
- Redis 6.2+
- RabbitMQ
- Docker and Docker Compose (for containerized deployment)
Installation
1. Clone the Repository
git clone https://github.com/yourusername/ff-messaging-service.git
cd ff-messaging-service
2. Set Up Environment Variables
Create a .env file in the project root:
SECRET_KEY=your_flask_secret_key
JWT_SECRET_KEY=your_jwt_secret_key
MONGO_URL=mongodb://mongo:27017
CACHE_REDIS_URL=redis://redis:6379/3
ES_HOST=http://elasticsearch:9200
FEATURE_FLAGS_PATH=feature_flags.json
RATELIMIT_DEFAULT=200 per day;50 per hour
3. Using Docker Compose
docker-compose up --build
This will start:
- Web service on port 5000
- MongoDB on port 27017
- Redis on port 6379
4. Manual Installation
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # Linux/Mac
.venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt
# Run the service
python wsgi.py
Basic Configuration
The service can be configured through environment variables or the config.py file:
SECRET_KEY: Flask secret keyJWT_SECRET_KEY: JWT encryption keyMONGO_URL: MongoDB connection stringCACHE_REDIS_URL: Redis connection stringFEATURE_FLAGS_PATH: Path to feature flags JSON fileRATELIMIT_DEFAULT: Default rate limiting rules
Feature Flags
Feature flags are managed through feature_flags.json:
{
"enable_read_receipts": true,
"enable_user_presence": true,
"enable_offline_delivery": true,
"enable_typing_indicators": true,
"enable_rate_limiting": true
}
Health Check
The service provides a basic health check endpoint at /:
curl http://localhost:5000/
Documentation Access
API documentation is available at:
http://localhost:5000/documentation